/*
 * @Author: 周海 zhouhaib@yonyou.com
 * @Date: 2022-12-18 11:16:15
 * @LastEditors: 周海 zhouhaib@yonyou.com
 * @LastEditTime: 2022-12-18 12:15:46
 */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { getServer } from '@/api/monitor/sysserver';
import PageDiv from '@/components/PageDiv';
import { useStore } from '@/store';
import { Card, Col, Row } from 'antd';
import React, { useEffect, useState } from 'react'
import './index.less';
const SysServer: React.FC = () => {
    const { layoutStore } = useStore();

    const [server, setServer] = useState<any>({});

    useEffect(() => {
        layoutStore.OpenSpanning()
        getServer().then((res) => {
            setServer(res.data)
        }).finally(() => layoutStore.CloseSpanning())
    }, [])

    return (
        <PageDiv>
            <Row className='server-row'>
                <Col span={12}>
                    <Card title="CPU" className='server-card'>
                        <Row gutter={[4, 4]} align={'bottom'} justify={'center'} className='cache-row'>
                            <Col span={12}>属性</Col>
                            <Col span={12}>值</Col>
                            <Col span={12}>核心数</Col>
                            <Col span={12}>{server?.cpu?.cpuNum}</Col>
                            <Col span={12}>用户使用率</Col>
                            <Col span={12}>{server?.cpu?.used}%</Col>
                            <Col span={12}>系统使用率</Col>
                            <Col span={12}>{server?.cpu?.sys}%</Col>
                            <Col span={12}>当前空闲率</Col>
                            <Col span={12}>{server?.cpu?.free}%</Col>
                        </Row>
                    </Card>
                </Col>
                <Col span={12}>
                    <Card title="内存" className='server-card'>
                        <Row gutter={[4, 4]} align={'bottom'} justify={'center'} className='cache-row'>
                            <Col span={8}>属性</Col>
                            <Col span={8}>内存</Col>
                            <Col span={8}>JVM</Col>
                            <Col span={8}>总内存</Col>
                            <Col span={8}>{server?.mem?.total}</Col>
                            <Col span={8}>{server?.jvm?.total}</Col>
                            <Col span={8}>已用内存</Col>
                            <Col span={8}>{server?.mem?.used}</Col>
                            <Col span={8}>{server?.jvm?.used}</Col>
                            <Col span={8}>剩余内存</Col>
                            <Col span={8}>{server?.mem?.free}G</Col>
                            <Col span={8}>{server?.jvm?.free}M</Col>
                            <Col span={8}>使用率</Col>
                            <Col span={8}>{server?.mem?.usage}%</Col>
                            <Col span={8}>{server?.jvm?.usage}%</Col>
                        </Row>
                    </Card>
                </Col>

                <Col span={24}>
                    <Card title="服务器信息" className='server-card'>
                        <Row align={'bottom'} justify={'space-between'}>
                            <Col span={10}>
                                <Row gutter={[4, 4]} align={'bottom'} justify={'start'} className='cache-row'>
                                    <Col span={10}>服务器名称</Col>
                                    <Col span={10}>{server.sys?.computerName}</Col>
                                    <Col span={10}>服务器IP</Col>
                                    <Col span={10}>{server.sys?.computerIp}</Col>
                                </Row>
                            </Col>
                            <Col span={10}>
                                <Row gutter={[4, 4]} align={'bottom'} justify={'end'} className='cache-row'>
                                    <Col span={10}>操作系统</Col>
                                    <Col span={10}>{server.sys?.osName}</Col>
                                    <Col span={10}>系统架构</Col>
                                    <Col span={10}>{server.sys?.osArch}</Col>
                                </Row>
                            </Col>
                        </Row>
                    </Card>
                </Col>
                <Col span={24}>
                    <Card title="JAVA虚拟机信息" className='server-card'>
                        <Row gutter={[4, 4]} align={'bottom'} justify={'center'} className='cache-row'>
                            <Col span={6}>JAVA名称</Col>
                            <Col span={6}>{server.jvm?.name}</Col>
                            <Col span={6}>JAVA版本</Col>
                            <Col span={6}>{server.jvm?.version}</Col>
                            <Col span={6}>启动时间</Col>
                            <Col span={6}>{server.jvm?.startTime}</Col>
                            <Col span={6}>运行时长</Col>
                            <Col span={6}>{server.jvm?.runTime}</Col>
                            <Col span={6}>安装路径</Col>
                            <Col span={18}>{server.jvm?.home}</Col>
                            <Col span={6}>项目路径</Col>
                            <Col span={18}>{server.sys?.userDir}</Col>
                            <Col span={6}>运行参数</Col>
                            <Col span={18}>{server.jvm?.inputArgs}</Col>
                        </Row>
                    </Card>
                </Col>
                <Col span={24}>
                    <Card title="磁盘状态" className='server-card'>
                        <Row gutter={[4, 4]} align={'bottom'} justify={'space-around'} className='cache-row'>
                            <Col span={3}>盘符路径</Col>
                            <Col span={3}>文件系统</Col>
                            <Col span={3}>盘符类型</Col>
                            <Col span={3}>总大小</Col>
                            <Col span={3}>可用大小</Col>
                            <Col span={3}>已用大小</Col>
                            <Col span={3}>已用百分比</Col>
                        </Row>
                        <Row gutter={[4, 4]} align={'bottom'} justify={'space-around'} className='cache-row'>
                            <Col span={3}>{server.sysFiles?.[0]?.dirName}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.sysTypeName}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.typeName}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.total}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.free}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.used}</Col>
                            <Col span={3}>{server.sysFiles?.[0]?.usage}%</Col>
                        </Row>
                    </Card>
                </Col>
            </Row>
        </PageDiv>
    )
}
export default SysServer;